package com.datawin.taotaocheche.ui.actviity.user.presenter;

import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import javax.inject.Inject;

import com.datawin.taotaocheche.base.BaseBiz;
import com.datawin.taotaocheche.comm.MyApplication;
import com.datawin.taotaocheche.ui.actviity.user.biz.ApplyCustomBiz;
import com.datawin.taotaocheche.ui.actviity.user.contract.ApplyCustomContract;

public class ApplyCustomPresenter implements ApplyCustomContract.Presenter {

    private ApplyCustomContract.View mView;
    private ApplyCustomBiz mBiz;

    @Inject
    public ApplyCustomPresenter(ApplyCustomContract.View view) {
        this.mView = view;
    }

    @Override
    public void setBiz(BaseBiz biz) {
        mBiz = (ApplyCustomBiz) biz;
    }

    @Override
    public void applyCommit(String count) {
        if (TextUtils.isEmpty(count)) {
            mView.showMsg("请输入申请定制数量");
            return;
        }
        mView.loading(true);
        mBiz.applyAdd(MyApplication.userInfo.getUserCode(), count, new BaseBiz.Callback<Object>() {

            @Override
            public void onSuccess(Object o) {
                mView.loading(false);
                mView.showMsg("申请定制成功");
                mView.finishAct();
            }

            @Override
            public void onFailure(Object o) {
                mView.loading(false);
                mView.showMsg("申请定制失败");
            }
        });
    }

    @Override
    public void telPhone(String tel) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + tel);
        intent.setData(data);
        mView.startAct(intent);
    }
}
